From 3f54e6d5ece9b20caa0fd77d2c8342c69c6733b2 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Wed, 6 Jul 2005 08:50:11 +0000 Subject: [PATCH] Attached is a patch that fully 'grant-table-ifies' the block front and backends. It is necessary to do a make clean in the tools directory and then rebuild the tree. Signed-off-by: Stefan Berger --- .../drivers/xen/blkback/common.h | 5 ++ .../drivers/xen/blkback/interface.c | 52 +++++++++++++++++++ .../drivers/xen/blkfront/blkfront.c | 13 +++-- tools/python/xen/lowlevel/xu/xu.c | 3 ++ tools/python/xen/xend/server/blkif.py | 3 +- xen/include/public/dom0_ops.h | 2 +- xen/include/public/io/domain_controller.h | 2 + 7 files changed, 75 insertions(+), 5 deletions(-) diff --git a/linux-2.6.11-xen-sparse/drivers/xen/blkback/common.h b/linux-2.6.11-xen-sparse/drivers/xen/blkback/common.h index a698e01c64..f3331a06a9 100644 --- a/linux-2.6.11-xen-sparse/drivers/xen/blkback/common.h +++ b/linux-2.6.11-xen-sparse/drivers/xen/blkback/common.h @@ -65,6 +65,11 @@ typedef struct blkif_st { atomic_t refcnt; struct work_struct work; +#ifdef CONFIG_XEN_BLKDEV_GRANT + u16 shmem_handle; + memory_t shmem_vaddr; + grant_ref_t shmem_ref; +#endif } blkif_t; void blkif_create(blkif_be_create_t *create); diff --git a/linux-2.6.11-xen-sparse/drivers/xen/blkback/interface.c b/linux-2.6.11-xen-sparse/drivers/xen/blkback/interface.c index f6bf04fe5b..4aaef6b116 100644 --- a/linux-2.6.11-xen-sparse/drivers/xen/blkback/interface.c +++ b/linux-2.6.11-xen-sparse/drivers/xen/blkback/interface.c @@ -39,6 +39,23 @@ static void __blkif_disconnect_complete(void *arg) * must still be notified to the remote driver. */ unbind_evtchn_from_irq(blkif->evtchn); + +#ifdef CONFIG_XEN_BLKDEV_GRANT + { + /* + * Release the shared memory page. + */ + struct gnttab_unmap_grant_ref op; + + op.host_virt_addr = blkif->shmem_vaddr; + op.handle = blkif->shmem_handle; + op.dev_bus_addr = 0; + + if(unlikely(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1))) { + BUG(); + } + } +#endif vfree(blkif->blk_ring.sring); /* Construct the deferred response message. */ @@ -154,8 +171,12 @@ void blkif_connect(blkif_be_connect_t *connect) unsigned int evtchn = connect->evtchn; unsigned long shmem_frame = connect->shmem_frame; struct vm_struct *vma; +#ifdef CONFIG_XEN_BLKDEV_GRANT + int ref = connect->shmem_ref; +#else pgprot_t prot; int error; +#endif blkif_t *blkif; blkif_sring_t *sring; @@ -174,6 +195,7 @@ void blkif_connect(blkif_be_connect_t *connect) return; } +#ifndef CONFIG_XEN_BLKDEV_GRANT prot = __pgprot(_KERNPG_TABLE); error = direct_remap_area_pages(&init_mm, VMALLOC_VMADDR(vma->addr), shmem_frame<addr); return; } +#else + { /* Map: Use the Grant table reference */ + struct gnttab_map_grant_ref op; + op.host_virt_addr = VMALLOC_VMADDR(vma->addr); + op.flags = GNTMAP_host_map; + op.ref = ref; + op.dom = domid; + + if(unlikely(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1))) { + BUG(); + } + + handle = op.handle; + + if (op.handle < 0) { + DPRINTK(" Grant table operation failure !\n"); + connect->status = BLKIF_BE_STATUS_MAPPING_ERROR; + vfree(vma->addr); + return; + } + + phys_to_machine_mapping[__pa(VMALLOC_VMADDR(vma->addr)) >> + PAGE_SHIFT] = + FOREIGN_FRAME(shmem_frame); + + blkif->shmem_ref = ref; + blkif->shmem_handle = handle; + blkif->shmem_vaddr = VMALLOC_VMADDR(vma->addr); + } +#endif if ( blkif->status != DISCONNECTED ) { diff --git a/linux-2.6.11-xen-sparse/drivers/xen/blkfront/blkfront.c b/linux-2.6.11-xen-sparse/drivers/xen/blkfront/blkfront.c index 7d1fb03ab6..07dd06fed6 100644 --- a/linux-2.6.11-xen-sparse/drivers/xen/blkfront/blkfront.c +++ b/linux-2.6.11-xen-sparse/drivers/xen/blkfront/blkfront.c @@ -1136,6 +1136,12 @@ static void blkif_send_interface_connect(void) msg->handle = 0; msg->shmem_frame = (virt_to_machine(blk_ring.sring) >> PAGE_SHIFT); +#ifdef CONFIG_XEN_BLKDEV_GRANT + msg->shmem_ref = gnttab_claim_grant_reference( &gref_head, gref_terminal ); + ASSERT( msg->shmem_ref != -ENOSPC ); + gnttab_grant_foreign_access_ref ( msg->shmem_ref , rdomid, msg->shmem_frame, 0 ); +#endif + ctrl_if_send_message_block(&cmsg, NULL, 0, TASK_UNINTERRUPTIBLE); } @@ -1261,9 +1267,6 @@ static void blkif_connect(blkif_fe_interface_status_t *status) blkif_evtchn = status->evtchn; blkif_irq = bind_evtchn_to_irq(blkif_evtchn); -#ifdef CONFIG_XEN_BLKDEV_GRANT - rdomid = status->domid; -#endif err = request_irq(blkif_irq, blkif_int, SA_SAMPLE_RANDOM, "blkif", NULL); if ( err ) @@ -1300,6 +1303,10 @@ static void unexpected(blkif_fe_interface_status_t *status) static void blkif_status(blkif_fe_interface_status_t *status) { +#ifdef CONFIG_XEN_BLKDEV_GRANT + rdomid = status->domid; /* need to set rdomid early */ +#endif + if ( status->handle != blkif_handle ) { WPRINTK(" Invalid blkif: handle=%u\n", status->handle); diff --git a/tools/python/xen/lowlevel/xu/xu.c b/tools/python/xen/lowlevel/xu/xu.c index 621de6272b..9c2663fbf0 100644 --- a/tools/python/xen/lowlevel/xu/xu.c +++ b/tools/python/xen/lowlevel/xu/xu.c @@ -594,6 +594,7 @@ static PyObject *xu_message_get_payload(PyObject *self, PyObject *args) case TYPE(CMSG_BLKIF_FE, CMSG_BLKIF_FE_INTERFACE_CONNECT): C2P(blkif_fe_interface_connect_t, handle, Int, Long); C2P(blkif_fe_interface_connect_t, shmem_frame, Int, Long); + C2P(blkif_fe_interface_connect_t, shmem_ref , Int, Long); return dict; case TYPE(CMSG_BLKIF_FE, CMSG_BLKIF_FE_INTERFACE_DISCONNECT): C2P(blkif_fe_interface_disconnect_t, handle, Int, Long); @@ -612,6 +613,7 @@ static PyObject *xu_message_get_payload(PyObject *self, PyObject *args) C2P(blkif_be_connect_t, domid, Int, Long); C2P(blkif_be_connect_t, blkif_handle, Int, Long); C2P(blkif_be_connect_t, shmem_frame, Int, Long); + C2P(blkif_be_connect_t, shmem_ref, Int, Long); C2P(blkif_be_connect_t, evtchn, Int, Long); C2P(blkif_be_connect_t, status, Int, Long); return dict; @@ -842,6 +844,7 @@ static PyObject *xu_message_new(PyObject *self, PyObject *args) P2C(blkif_be_connect_t, domid, u32); P2C(blkif_be_connect_t, blkif_handle, u32); P2C(blkif_be_connect_t, shmem_frame, memory_t); + P2C(blkif_be_connect_t, shmem_ref, u32); P2C(blkif_be_connect_t, evtchn, u16); break; case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_DISCONNECT): diff --git a/tools/python/xen/xend/server/blkif.py b/tools/python/xen/xend/server/blkif.py index dac65c426b..7fcd751652 100755 --- a/tools/python/xen/xend/server/blkif.py +++ b/tools/python/xen/xend/server/blkif.py @@ -126,7 +126,8 @@ class BlkifBackend: { 'domid' : self.frontendDomain, 'blkif_handle' : self.id, 'evtchn' : self.getEventChannelBackend(), - 'shmem_frame' : val['shmem_frame'] }) + 'shmem_frame' : val['shmem_frame'], + 'shmem_ref' : val['shmem_ref'] }) msg = self.backendChannel.requestResponse(msg) #todo: check return status val = unpackMsg('blkif_be_connect_t', msg) diff --git a/xen/include/public/dom0_ops.h b/xen/include/public/dom0_ops.h index 419e647746..0c539ea11b 100644 --- a/xen/include/public/dom0_ops.h +++ b/xen/include/public/dom0_ops.h @@ -19,7 +19,7 @@ * This makes sure that old versions of dom0 tools will stop working in a * well-defined way (rather than crashing the machine, for instance). */ -#define DOM0_INTERFACE_VERSION 0xAAAA100B +#define DOM0_INTERFACE_VERSION 0xAAAA100C /************************************************************************/ diff --git a/xen/include/public/io/domain_controller.h b/xen/include/public/io/domain_controller.h index 3a9f2e8bf7..ddd140ae42 100644 --- a/xen/include/public/io/domain_controller.h +++ b/xen/include/public/io/domain_controller.h @@ -140,6 +140,7 @@ typedef struct blkif_fe_driver_status { typedef struct blkif_fe_interface_connect { u32 handle; memory_t shmem_frame; + int shmem_ref; } blkif_fe_interface_connect_t; /* @@ -249,6 +250,7 @@ typedef struct blkif_be_connect { domid_t domid; /* Domain attached to new interface. */ u32 blkif_handle; /* Domain-specific interface handle. */ memory_t shmem_frame; /* Page cont. shared comms window. */ + int shmem_ref; /* Grant table reference. */ u32 evtchn; /* Event channel for notifications. */ /* OUT */ u32 status; -- 2.30.2